<template>
  <router-view></router-view>
</template>
<script>
  import { mapState, mapActions } from 'vuex'
  export default {
    name: 'app',
    computed: {
      ...mapState(['cityMsg', 'factoryMsg', 'productMsg', 'repairMsg'])
    },
    created () {
      this.setRouter()
      // 城市
      this.getCityData()
      // 厂商
      this.getFactoryData()
      // 产品
      this.getProductData()
      // 报修原因
      this.getRepairMsgData()
    },
    methods: {
      ...mapActions(['getCityMsg', 'getFactoryMsg', 'getProductMsg', 'getRepairMsg']),
      setRouter () {
        let username = JSON.parse(sessionStorage.getItem('username'))
        let router = JSON.parse(sessionStorage.getItem('router'))
        if (username && router) {
          this.$router.addRoutes(this.shiftyRouter(router))
        } else {
          this.$router.push('/login')
        }
      },
      // 获取城市信息
      getCityData () {
        let url = this.api2.city.info
        let obj = {
          url: url,
          msg: this.$message
        }
        this.getCityMsg(obj)
      },
      // 获取厂商信息
      getFactoryData () {
        let url = this.api2.factory.info
        let obj = {
          url: url,
          msg: this.$message
        }
        this.getFactoryMsg(obj)
      },
      // 获取产品信息
      getProductData () {
        let url = this.api2.product.info
        let obj = {
          url: url,
          msg: this.$message
        }
        this.getProductMsg(obj)
      },
      // 获取报修原因
      getRepairMsgData () {
        let url = this.api2.repair.info
        let obj = {
          url: url,
          msg: this.$message
        }
        this.getRepairMsg(obj)
      }
    }
  }
</script>
